package com.study.clickhouse.controller;

import com.study.clickhouse.model.VisitStatsDO;
import com.study.clickhouse.request.PageRequest;
import com.study.clickhouse.request.SelectRegionCityRequest;
import com.study.clickhouse.service.VisitStatsService;
import com.study.clickhouse.util.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/clickhouse")
public class VisitStatsController {


    @Autowired
    private VisitStatsService visitStatsService;

    /**
     * 分页查询
     * @param pageRequest
     * @return
     */
    @GetMapping("selectPageClickhouse")
    public JsonData selectPageClickhouse(@ModelAttribute PageRequest pageRequest){

        Map<String, Object> map = visitStatsService.selectPageClickhouse(pageRequest);
        return JsonData.buildSuccess(map);
    }


    /**
     * 根据区域，城市查询
     * @param selectRegionCityRequest
     * @return
     */
    @GetMapping("selectByRegionCity")
    public JsonData selectByRegionCity(@ModelAttribute SelectRegionCityRequest selectRegionCityRequest){
        List<VisitStatsDO> visitStatsDOList = visitStatsService.selectByRegionCity(selectRegionCityRequest);
        return JsonData.buildSuccess(visitStatsDOList);
    }
}
